package com.lz.football.module.youngTrain.view
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.core.TitleWindow;
	/**
	 * 获得球员面板 
	 * @author lake
	 * 
	 */	
	public class GetPlayerResultPanel extends TitleWindow implements IComponent
	{
		/**
		 *描述 
		 */		
		private var txtDesc 	:TextField;
		/**
		 *确认 
		 */		
		private var sureBtn	:SimpleButton;
		/**
		 *容器 
		 */		
		private var container	:MovieClip;
		/**
		 *数据 
		 */		
		private var _data		:*;
		
		public function GetPlayerResultPanel()
		{
			super();
		}
		/**
		 *设置获取数据 
		 * @param value
		 * 
		 */		
		public function set data(value :*):void
		{
			_data = value;
			//球星id
			var starId  :int = _data.starId;
			//原球童颜色
			var color	:int = _data.color;
			if(color <= 1)
			{
				color = 2;
			}
			var playerCard :* = Reflection.createInstance("com.liangzhong.view.tips.PlayerCardTips");
			var starVo	:PlayerStarVo = AppData.getInstance().goodsManager.getStarById(starId) as PlayerStarVo;
			if(playerCard)
			{
				container.addChild(playerCard as DisplayObject);
				playerCard.cdata = starVo;
			}
			var conf :XML = ResourceManager.instance.getResource(ResourceConst.YOUNGTRAIN_CONFIG);
			var colorRef :String = "color" + color;
			var resXmlList :XMLList;
			if(starVo && conf)
			{
				if(starVo.color >= color)//开出期望颜色
				{
					resXmlList = conf["" + colorRef][0].item.(@type==1);
				}
				else
				{
					resXmlList = conf["" + colorRef][0].item.(@type==2);
				}
			}
			var len :int;
			var ramIndex :int;
			if(resXmlList)
			{
				len = resXmlList.length();
				ramIndex = len * Math.random();
				//设置描述内容
				var info :String = "" + String(resXmlList[ramIndex]);
				info = info.replace("XXX",starVo.pname);
				txtDesc.htmlText = info;
			}
		}
		public function get data():*
		{
			return _data;
		}
		/**
		 *初始化 
		 */	
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.youngtrain.getPlayerResultSkin");
			this.addChild(_symbolSkin);
			txtDesc = _symbolSkin.txtDesc;
			sureBtn = _symbolSkin.sureBtn;
			//背景框
			windowBg = _symbolSkin.windowBg;
			//球员卡容器
			container = _symbolSkin.container;
			//设置可拖动
			dragEnabled = true;
			//初始化宽高
			width 	= _symbolSkin.width;
			height	= _symbolSkin.height;
			//设置关闭按钮
			setCloseBtn(_symbolSkin.closeBtn);
			//添加事件
			addEvtListener();
		}
		/**
		 *注册事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			sureBtn.addEventListener(MouseEvent.CLICK,onCloseHandler);
		}
		/**
		 *关闭 
		 * @param e
		 * 
		 */		
		override protected function onCloseHandler(e:MouseEvent):void
		{
			super.onCloseHandler(e);
			destroyView();
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			sureBtn.removeEventListener(MouseEvent.CLICK,onCloseHandler);
		}
		/**
		 *销毁 
		 * 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
		}
	}
}